﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TakePhotoTogether.Communication.Protocols
{
    public class RoundTripTimeData : PayloadData
    {

        public bool returningTravel = false;

        public DateTime currentTime;
        

        public RoundTripTimeData()
        {
            currentTime = DateTime.Now;
        }

        public RoundTripTimeData(bool travel)
        {
            currentTime = DateTime.Now;

            returningTravel = travel;
        }

        public RoundTripTimeData(byte[] data)
        {
            returningTravel = ((int)data[0] == 1);

            long tick = BitConverter.ToInt64(data, 1);

            currentTime = DateTime.FromBinary(tick);
        }

        public byte[] ToBytes()
        {
            byte[] dateBytes = BitConverter.GetBytes(currentTime.Ticks);

            byte[] data = new byte[dateBytes.Length + 1];

            data[0] = (byte)(returningTravel ? 1 : 0);

            for (int i = 1; i < data.Length; i++)
            {
                data[i] = dateBytes[i - 1];
            }
            
            return data;
        }
    }
}
